package com.newedu.equipmgr.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * @author jerry
 * @create 2020-06-02 08:06:10
 * @company 新开普电子股份有限公司
 */
@WebServlet(name = "LogoutServlet", urlPatterns = "/servlet/LogoutServlet")
public class LogoutServet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        /**
         * 1. 清空session中的数据
         * 2. 重定向到login.jsp
         */
        // 通过request获取session域对象
        HttpSession session = request.getSession();

        // Invalidates 销毁当前用户的session对象，并解绑所有关联的对象数据
        //  1. 清空session中的数据
        session.invalidate();

        // 2. 重定向到login.jsp
        response.sendRedirect(request.getContextPath()+"/login.jsp");

    }
}

